<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 函数封装[1,4,5,6,7,8,9,11,34,56,78] 过滤掉大于20的数，然后排序出来，求大于20的累加和
    function fn() {
      let arr = [1, 4, 5, 6, 7, 8, 9, 11, 34, 56, 78]
      const res = arr.filter(item => {
        if (item > 20) {
          return item
        }
      })
      // console.log(res);
      const obj = res.sort(function (a, b) {
        return a - b
      })
      const sum = obj.reduce((prev, item) => {
        return prev + item
      }, 0)
      console.log(sum);
    }
    fn()
  </script>
</body>

</html>